﻿using SUNRPA.CONTROLS.IMPL.domain.attrubutes;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;
using System.Globalization;
using System.Windows.Data;

namespace SUNRPA.CONTROLS.IMPL.domain.flowItemParam {
    [Serializable]
    [VarFieldName("MailListVar")]
    public class ReceiveEmailNParam:BaseParam {
        public ReceiveEmailNParam() { 
            ssl = false;
            tagReaded = true;
            saveAttachFile = false;
            unReadMail = true;
            mailListVar = "mailmessage_list";
        }
        //邮箱类型0阳光邮箱、1、163邮箱、2qq邮箱、3自定义邮箱
        private EmailType mailType = EmailType.SUN;
        //服务器
        private string serverName;
        private string port;
        private bool? ssl;
        //账号
        private string account;
        //授权码
        private string password;
        //读取邮件数量
        private int? mailNum;
        //仅未读邮件
        private bool? unReadMail;
        //保存附件
        private bool? saveAttachFile;
        //附件保存目录
        private string savePath;
        //邮件列表保存变量
        private string mailListVar;
        //文件夹指定0默认，1动态
        private int? dirType;
        //文件夹名称
        private string dirName;
        //标记为已读
        private bool? tagReaded;
        //发件人包括
        private string senderFilter;
        //收件人包括
        private string receiverFilter;
        //主题
        private string titleFilter;
        //正文
        private string contentFilter;
        //发送时间
        private DateTime sendDateFilter;

        public EmailType MailType { get => mailType; set { mailType = value; NotifyPropertyChanged("MailType");} }
        public string ServerName { get => serverName; set { serverName = value; NotifyPropertyChanged("ServerName");} }
        public string Port { get => port; set { port = value; NotifyPropertyChanged("Port");} }
        public bool? Ssl { get => ssl; set { ssl = value; NotifyPropertyChanged("Ssl");} }
        public string Account { get => account; set { account = value; NotifyPropertyChanged("Account");}}
        public string Password { get => password; set { password = value; NotifyPropertyChanged("Password");} }
        public int? MailNum { get => mailNum; set { mailNum = value; NotifyPropertyChanged("MailNum");} }
        public bool? UnReadMail { get => unReadMail; set{ unReadMail = value; NotifyPropertyChanged("UnReadMail");} }
        public bool? SaveAttachFile { get => saveAttachFile; set{ saveAttachFile = value; NotifyPropertyChanged("SaveAttachFile");} }
        public string SavePath { get => savePath; set{ savePath = value; NotifyPropertyChanged("SavePath");} }
        public string MailListVar { get => mailListVar; set{ mailListVar = value; NotifyPropertyChanged("MailListVar");}}
        public int? DirType { get => dirType; set { dirType = value; NotifyPropertyChanged("DirType");} }
        public string DirName { get => dirName; set { dirName = value; NotifyPropertyChanged("DirName");} }
        public bool? TagReaded { get => tagReaded; set { tagReaded = value; NotifyPropertyChanged("TabReaded");} }
        public string SenderFilter { get => senderFilter; set{ senderFilter = value; NotifyPropertyChanged("SenderFilter");} }
        public string ReceiverFilter { get => receiverFilter; set{ receiverFilter = value; NotifyPropertyChanged("ReceiverFilter");}}
        public string TitleFilter { get => titleFilter; set{ titleFilter = value; NotifyPropertyChanged("TitleFilter");} }
        public string ContentFilter { get => contentFilter; set { contentFilter = value; NotifyPropertyChanged("ContentFilter");} }
        public DateTime SendDateFilter { get => sendDateFilter; set { sendDateFilter = value; NotifyPropertyChanged("SendDateFilter");} }

        public string GetTranslateMailType() {
            switch(this.mailType) {
                case EmailType.SUN:
                    return "阳光邮箱";
                case EmailType.NETEASY:
                    return "163邮箱";
                case EmailType.QQ:
                    return "qq邮箱";
                case EmailType.CUSTOM:
                    return "自定义邮箱";
                default : return "阳光邮箱";
            }
        }

        public override void SetLatestVarName(ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData) {
            this.mailListVar = this.GetLatestName(this.mailListVar, globleData);
        }

    }

    public class MailTypeConverter:IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            return (int)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return Enum.Parse(typeof(EmailType), value.ToString());
        }
    }
}
